/*
 * Copyright 2014 Masatoshi sato.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sd_network.util;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * This is a utility class for String.
 * This class have various methods about String with character encoding.
 *
 * @author Masatoshi Sato
 */
public final class StringUtil
{
    /** Default Logger. */
    private static final Logger _log = Logger.getLogger(
            StringUtil.class.getName());

    //////////////////////////////////////////////////////////// 
    // Private fields.

    private StringUtil() {
        throw new UnsupportedOperationException(
                "This class have to not create instance.");
    }

    //////////////////////////////////////////////////////////// 
    // Public methods.

    /**
     * Check argument is null or zero length string.
     *
     * @param   str     target string.
     * @param   trim    if <tt>true</tt>, triming space charactors where 
     *                  head or last of string.
     *                  if not, do not triming space characters.
     *
     * @return  if <tt>str</tt> is <tt>null</tt> or zero length string,
     *          return <tt>true</tt>.
     *          if not return <tt>false</tt>.
     */
    public static final boolean isEmpty(String str, boolean trim) {
        if (str == null)
            return true;
        if (trim)
            str = str.trim();
        return (str.length() == 0);
    }
}
